/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;


/**
 *
 * @author Team 3502
 */
public class DriveToTargetPID extends CommandBase {

    //private double targetX;

    public DriveToTargetPID() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(drive);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        //use this if using gyro or encoders for PID loop
        //drive.initsensors();

        drive.findtarget();

        //set the target x (pixel) to be the center of the image
        //targetX = drive.getXcenter();
        //drive.setSetpoint(0.0);
        //drive.enable();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        //allows the robot to be pointed within +/- 5 pixels of the center of the target
        return Math.abs(flyPID.getPosition()) <= 0.1;
    }

    // Called once after isFinished returns true
    protected void end() {
        flyPID.disable();
        System.out.println("Robot Aligned!");
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        flyPID.disable();
    }
}